Ext.require(['Ext.data.*']);

Ext.onReady(function() {

    window.generateBuyDay = function(url){
        var data = [];
        $.ajax({
			type : 'get',
			url : url,
			data : '',
			async : false,
			success : function(response){
				if (response.success == true) {
					for(index in response.dishes) {
						var dish = response.dishes[index];
						data.push({
							'name': dish.name,
							'data1': dish.sum
						});
					}
				} else {
				}
			}
		});
        return data;
    };
    
    window.generateSales = function(url){
        var data = [];
        $.ajax({
			type : 'get',
			url : url,
			data : '',
			async : false,
			success : function(response){
				if (response.success == true) {
					for(index in response.sales) {
						var sale = response.sales[index];
						data.push({
							'name': sale.countDate,
							'data1': sale.sum
						});
					}
				} else {
				}
			}
		});
        return data;
    };

    window.store1 = Ext.create('Ext.data.JsonStore', {
        fields: ['name', 'data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7', 'data9', 'data9'],
        data: generateBuyDay('../dish/day/top')
    });
    window.store2 = Ext.create('Ext.data.JsonStore', {
        fields: ['name', 'data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7', 'data9', 'data9'],
        data: generateBuyDay('../dish/week/top')
    });
    window.store3 = Ext.create('Ext.data.JsonStore', {
        fields: ['name', 'data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7', 'data9', 'data9'],
        data: generateBuyDay('../dish/month/top')
    });
    window.store4 = Ext.create('Ext.data.JsonStore', {
        fields: ['name', 'data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7', 'data9', 'data9'],
        data: generateSales('../sales/week')
    });
    window.store5 = Ext.create('Ext.data.JsonStore', {
        fields: ['name', 'data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7', 'data9', 'data9'],
        data: generateSales('../sales/month')
    });    
    
    window.loadTask = new Ext.util.DelayedTask();
});
